<template>
  <el-dialog
    title="选择设备"
    :visible="selectEquipmentDialog"
    width="70%"
    class="Equipment-select"
    @close="selectEquipmentClose"
  >
    <div class="app-container Equipment-box">
      <el-row :gutter="20">
        <el-col :span="24" :xs="24">
          <!-- 设备号数据 -->
          <el-table
            :data="equipmentData"
            border
            v-loading="loading"
            :height="maxHeight"
            @row-dblclick="handleEquipmentSelect"
          >
            <el-table-column
              type="index"
              width="60"
              align="center"
              label="序号"
            >
            </el-table-column>
            <el-table-column label="设备代码" align="center" prop="code">
            </el-table-column>
            <el-table-column label="设备名称" align="center" prop="name">
            </el-table-column>
            <el-table-column
              label="业务类型"
              align="center"
              prop="workTypeName"
            >
            </el-table-column>
            <el-table-column label="部门" align="center" prop="deptName">
            </el-table-column>
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding"
              width="80"
            >
              <template slot-scope="scope">
                <div class="public-btn">
                  <el-button
                    size="mini"
                    type="text"
                    @click.stop="handleEquipmentSelect(scope.row)"
                    >选择
                  </el-button>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
    </div>
  </el-dialog>
</template>
<script>
import { listEquipment } from "../../api/order";
let self;
export default {
  name: "Equipment",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 客户查询参数
      queryParams: {
        workType: "",
      },
      // 总条数
      total: 0,
      // 最大高度
      maxHeight: null,
      //设备数据
      equipmentData: [],
      // 是否显示弹出层
      open: false,
      // 弹出层标题
      title: "",

      //弹框提交按钮状态，1（新增） 2（修改）
      butChange: "",
    };
  },
  props: {
    selectEquipmentDialog: {
      type: Boolean,
      default: true,
    },
    workType: {
      type: String,
      default: "",
    },
    optionsworkType: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  beforeCreate() {
    self = this;
  },
  created() {
    this.getEquipmentlList();
  },
  methods: {
    // 获取设备数据
    getEquipmentlList() {
      this.loading = true;
      this.queryParams.workType = this.workType;
      listEquipment(this.queryParams).then((res) => {
        if (res.code == 200) {
          this.loading = false;
          this.equipmentData = res.rows;
          if (this.equipmentData.length > 0) {
            this.equipmentData.forEach((item) => {
              this.optionsworkType.forEach((obj) => {
                if (item.workType == obj.dictValue) {
                  item.workTypeName = obj.dictLabel;
                }
              });
            });
          }
          this.total = res.total;
          this.maxHeight = `${document.documentElement.clientHeight}` - 300;
        }
      });
    },

    // 弹框状态
    selectEquipmentClose() {
      this.$emit("selectEquipmentClose");
    },

    // 选择设备
    handleEquipmentSelect(row) {
      this.$emit("handleEquipmentSelect", row);
    },

    /** 弹框取消 */
    cancel() {
      this.open = false;
      this.reset();
    },
    close() {
      this.reset();
    },
  },
};
</script>
<style lang="scss">
.Equipment-in-dialog {
  .Billing-box {
    padding: 15px;
    box-shadow: 1px 1px 10px 1px #eee;
    border-radius: 5px;
    padding-bottom: 10px;
    margin: 10px 10px 0px 10px;

    h2 {
      font-size: 15px;
      font-weight: 700;
      margin: 0;
      border-bottom: 1px solid #dfe6ec;
      padding-bottom: 15px;
      margin-bottom: 15px;
    }
  }

  .el-input.is-disabled .el-input__inner {
    color: #333;
  }
}

.Equipment-select {
  .el-dialog__body {
    height: calc(100vh - 250px);
  }
  .el-range-editor--medium.el-input__inner {
    line-height: 32px;
  }
  .el-range-editor--medium .el-range__icon,
  .el-range-editor--medium .el-range__close-icon,
  .el-range-editor--medium .el-range-separator {
    line-height: 24px;
  }
  .el-range-editor--medium.el-input__inner {
    height: 32px;
  }
  .custom-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .app-container {
    padding-top: 0;
  }

  .el-table {
    cursor: pointer;
  }

  .el-table__body {
    user-select: none;
  }

  .Equipment-box {
    .el-tag.el-tag--info {
      color: #1890ff;
    }

    .Billing-box {
      padding: 15px;
      box-shadow: 1px 1px 10px 1px #eee;
      border-radius: 5px;
      padding-bottom: 10px;
      margin: 10px 10px 0px 10px;

      h2 {
        font-size: 15px;
        font-weight: 700;
        margin: 0;
        border-bottom: 1px solid #dfe6ec;
        padding-bottom: 15px;
        margin-bottom: 15px;
      }
    }

    .el-switch {
      display: flex;
      justify-content: center;
    }

    .el-radio__input.is-disabled.is-checked .el-radio__inner {
      background-color: #f5f7fa;
      border-color: #999;
    }

    .el-radio {
      margin-right: 18px;
    }

    .el-radio__label {
      padding-left: 5px;
    }

    .el-radio:nth-of-type(3) {
      margin-right: 0;
    }

    .el-switch.is-disabled {
      opacity: 1;
    }

    .el-table .el-table__header-wrapper th,
    .el-table .el-table__fixed-header-wrapper th {
      height: 35px;
    }

    .el-dialog__body {
      padding-right: 15px;
      padding-bottom: 20px;
    }

    .el-input.is-disabled .el-input__inner {
      color: #333;
    }

    .el-form-item--medium .el-form-item__content {
      margin-right: 10px !important;
    }
  }

  .close-select {
    overflow: hidden;

    i {
      float: right;
      margin-right: 15px;
      color: #909399;
      cursor: pointer;
    }
  }
}
</style>
